﻿using Shinva.LADModel.Abstractions;
using Shinva.Variables.Interface;
using Shinva.Variables.Type.bit;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shinva.LADModel.Models
{
    //这个是母线节点，简单做为标示用
    public class Powerrail : IGraphNode
    {
        public int Id { get; set; }
        public NodeType NodeType { get; set; } = NodeType.NetNode;

        //母线输出触点
        public PlcBool eno { get; set; } = new PlcBool() { Value = false };

        //这个网络中所有的使能线
        public List<Connector<PlcBool>> enableLines { get; set; } = new List<Connector<PlcBool>>();


        /// <summary>
        /// 连接到图元节点
        /// </summary>
        /// <param name="element"></param>
        public void Connect(IGraphNode element, string FromName, string ToName)
        {
            var test = new Connector<PlcBool>();
            test.From = this.eno;
            test.FromNode = this;

            test.To = (PlcBool)element.GetInterfaceVariableByName(ToName);
            test.ToNode = element;

            enableLines.Add(test);
        }



        public IPlcMember GetInterfaceVariableByName(string name)
        {
            if(name == "out")
            {
                return eno;
            }
            else
            {
                return default;
            }
        }

        private int _counter;
        public int counter
        {
            get
            {
                return _counter++;
            }
            set
            {
                _counter = value;
            }
        }
    }
}
